package com.jl.jlapp.mvp.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import com.jl.jlapp.R;
import com.jl.jlapp.eneity.PostModel;
import com.jl.jlapp.nets.Api;
import com.jl.jlapp.nets.Net;
import com.jl.jlapp.popu.ClearHistorySearhPopu;

import org.reactivestreams.Subscription;

import io.reactivex.Flowable;
import io.reactivex.FlowableSubscriber;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class AddGeneralInvoiceActivity
        extends Activity {
    @BindView(R.id.add_page_top_del)
    TextView addPageTopDel;
    ClearHistorySearhPopu clearHistorySearhPopu = null;
    @BindView(R.id.et_taxpayer_identification_number)
    EditText etTaxpayerIdentificationNumber;
    @BindView(R.id.et_unit_name)
    EditText etUnitName;
    public OnClickListener itemclick = new OnClickListener() {
        public void onClick(View paramAnonymousView) {
            AddGeneralInvoiceActivity.this.clearHistorySearhPopu.dismiss();
            AddGeneralInvoiceActivity.this.deleteInvoiceUnitById(AddGeneralInvoiceActivity.this.unitId, AddGeneralInvoiceActivity.this.userId);
        }
    };
    @BindView(R.id.page_title)
    TextView pageTitle;
    @BindView(R.id.save_general_invoice_linear)
    LinearLayout saveGeneralInvoiceLinear;
    String taxpayerIdentificationNumber = "";
    int unitId = 0;
    String unitName = "";
    int userId = 0;
    int whichButton = -1;

    public void addInvoiceUnit(String paramString1, String paramString2, int paramInt) {
        Net.get().addInvoiceUnit(paramString1, paramString2, paramInt).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<PostModel>() {


            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(PostModel postModel) {

            }

            @Override
            public void onError(Throwable t) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    public void deleteInvoiceUnitById(int paramInt1, int paramInt2) {
        Net.get().deleteInvoiceUnitById(paramInt1, paramInt2).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<PostModel>() {


            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(PostModel postModel) {

            }

            @Override
            public void onError(Throwable t) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

    @OnClick({R.id.save_general_invoice_linear, R.id.add_page_top_del, R.id.return_btn})
    public void onClick(View paramView) {
        String str1 = this.etUnitName.getText().toString().trim();
        String str2 = this.etTaxpayerIdentificationNumber.getText().toString().trim();
        switch (paramView.getId()) {
            case R.id.save_general_invoice_linear:
                if ("".equals(str1)) {
                    Toast.makeText(this, "请输入单位名称", Toast.LENGTH_SHORT).show();
                    return;
                }
                if ("".equals(str2)) {
                    Toast.makeText(this, "请输入纳税人识别号", Toast.LENGTH_SHORT).show();
                    return;
                }
                addInvoiceUnit(str1, str2, this.userId);
                break;
            case R.id.add_page_top_del:
                break;
            case R.id.return_btn:
                finish();
                break;
        }
//        do {
//            do {
//                return;
//
//            } while (this.whichButton != 1);
//            updateInvoiceUnitById(this.unitId, this.userId, str1, str2);
//            return;
//            this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, this.itemclick, Integer.valueOf(8));
//            this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.add_unit_page), 17, 0, 0);
//            return;
//            if (this.whichButton == 0) {
//                if ((!"".equals(str1)) || (!"".equals(str2))) {
//                    this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener() {
//                        public void onClick(View paramAnonymousView) {
//                            AddGeneralInvoiceActivity.this.clearHistorySearhPopu.dismiss();
//                            AddGeneralInvoiceActivity.this.finish();
//                        }
//                    }, Integer.valueOf(9));
//                    this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.add_unit_page), 17, 0, 0);
//                    return;
//                }
//                finish();
//                return;
//            }
//        } while (this.whichButton != 1);
//        if (((!"".equals(str1)) && (!this.unitName.equals(str1))) || ((!"".equals(str2)) && (!this.taxpayerIdentificationNumber.equals(str2)))) {
//            this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener() {
//                public void onClick(View paramAnonymousView) {
//                    AddGeneralInvoiceActivity.this.clearHistorySearhPopu.dismiss();
//                    AddGeneralInvoiceActivity.this.finish();
//                }
//            }, Integer.valueOf(9));
//            this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.add_unit_page), 17, 0, 0);
//            return;
//        }
    }

    protected void onCreate(Bundle paramBundle) {
        super.onCreate(paramBundle);
        setContentView(R.layout.activity_add_general_invoice);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        this.whichButton = intent.getIntExtra("whichButton", -1);
        this.unitId = intent.getIntExtra("unitId", 0);
        this.unitName = intent.getStringExtra("unitName");
        this.taxpayerIdentificationNumber = intent.getStringExtra("taxpayerIdentificationNumber");
        if (this.whichButton == 0) {
            this.pageTitle.setText("新增公司信息");
            this.addPageTopDel.setVisibility(View.GONE);
            return;
        }
        if ((this.whichButton == 1) && (this.unitId > 0) && (!"".equals(this.unitName)) && (!"".equals(this.taxpayerIdentificationNumber))) {
            this.pageTitle.setText("编辑公司信息");
            this.addPageTopDel.setVisibility(View.VISIBLE);
            this.etUnitName.setText(this.unitName);
            this.etTaxpayerIdentificationNumber.setText(this.taxpayerIdentificationNumber);
            return;
        }
        Toast.makeText(this, "页面传值错误", Toast.LENGTH_SHORT).show();
        this.saveGeneralInvoiceLinear.setVisibility(View.GONE);
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
        if ((paramInt == 4) && (paramKeyEvent.getRepeatCount() == 0)) {
            this.etUnitName.getText().toString().trim();
            String str = this.etTaxpayerIdentificationNumber.getText().toString().trim();
            if (this.whichButton == 0) {
                if ((!"".equals(paramKeyEvent)) || (!"".equals(str))) {
                    this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener() {
                        public void onClick(View paramAnonymousView) {
                            AddGeneralInvoiceActivity.this.clearHistorySearhPopu.dismiss();
                            AddGeneralInvoiceActivity.this.finish();
                        }
                    }, Integer.valueOf(9));
                    this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.add_unit_page), 17, 0, 0);
                }
            }
//            while (this.whichButton != 1) {
//                return true;
//                finish();
//                return true;
//            }
            if (((!"".equals(paramKeyEvent)) && (!this.unitName.equals(paramKeyEvent))) || ((!"".equals(str)) && (!this.taxpayerIdentificationNumber.equals(str)))) {
                this.clearHistorySearhPopu = new ClearHistorySearhPopu(this, new OnClickListener() {
                    public void onClick(View paramAnonymousView) {
                        AddGeneralInvoiceActivity.this.clearHistorySearhPopu.dismiss();
                        AddGeneralInvoiceActivity.this.finish();
                    }
                }, Integer.valueOf(9));
                this.clearHistorySearhPopu.showAtLocation(findViewById(R.id.add_unit_page), 17, 0, 0);
                return true;
            }
            finish();
            return true;
        }
        return super.onKeyDown(paramInt, paramKeyEvent);
    }

    protected void onResume() {
        super.onResume();
        this.userId = getSharedPreferences("JLAppData", 0).getInt("userId", 0);
        if (this.userId <= 0) {
            Toast.makeText(this, "您还未登录，请先登录。", Toast.LENGTH_SHORT).show();
            startActivity(new Intent(this, LoginActivity.class));
        }
    }

    public void updateInvoiceUnitById(int paramInt1, int paramInt2, String paramString1, String paramString2) {
        Net.get().updateInvoiceUnitById(paramInt1, paramInt2, paramString1, paramString2).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<PostModel>() {


            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(PostModel postModel) {

            }

            @Override
            public void onError(Throwable t) {

            }

            @Override
            public void onComplete() {

            }
        });
    }
}


/* Location:              /Users/davidzhang/Documents/decompileApk/jlfood-dex2jar.jar!/com/jl/jlapp/mvp/activity/AddGeneralInvoiceActivity.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */